package org.myOrg.spetrum.io;

import java.util.Iterator;

import org.myOrg.spetrum.testObject.TestCase;
import org.myOrg.spetrum.testObject.TestCaseImplement;
import org.myOrg.spetrum.testObject.TestSuite;
import org.myOrg.spetrum.testObject.TestSuiteImplement;

public class ReaderImplement implements ReadSuite {
	int[] param;
	TestSuite testSuite;

	public ReaderImplement(){
		testSuite = new TestSuiteImplement();
	}
	@Override
	public void read(ValidateFormat validate) {
		// TODO Auto-generated method stub
		ValidateImplement va = (ValidateImplement) validate;
		this.param = va.getParam();
		readTestSuite(va , TestCase.FAILED);
		readTestSuite(va , TestCase.PASSED);

	}
	private void readTestSuite(ValidateImplement va ,int failedOrPassed) {
		
		Iterator<int[]> ite;
		if(failedOrPassed == TestCase.FAILED)
			ite = va.getFailedTests().iterator();
		else
			ite = va.getPassedTests().iterator();
		
		while (ite.hasNext()) {
           int[] temp = ite.next();
           TestCaseImplement test = new TestCaseImplement();
           test.setTestCase(temp);
           test.setTestState(failedOrPassed);
           testSuite.addTest(test);
		}
	}

	@Override
	public TestSuite getTestSuit() {
		// TODO Auto-generated method stub
		return this.testSuite;
	}

	@Override
	public int[] getParam() {
		// TODO Auto-generated method stub
		return this.param;
	}

}
